using MauiBuilder.Models;

namespace MauiBuilder.Services;

/// <summary>
/// 支付服务接口
/// </summary>
public interface IPaymentService
{
    /// <summary>
    /// 初始化支付配置
    /// </summary>
    /// <param name="config">支付配置</param>
    Task InitializeAsync(PaymentConfig config);
    
    /// <summary>
    /// 创建支付订单
    /// </summary>
    /// <param name="request">支付请求</param>
    /// <returns>支付响应</returns>
    Task<PaymentResponse> CreatePaymentAsync(PaymentRequest request);
    
    /// <summary>
    /// 查询支付结果
    /// </summary>
    /// <param name="orderId">订单号</param>
    /// <returns>支付结果</returns>
    Task<PaymentResult> QueryPaymentAsync(string orderId);
    
    /// <summary>
    /// 取消支付
    /// </summary>
    /// <param name="orderId">订单号</param>
    /// <returns>是否成功</returns>
    Task<bool> CancelPaymentAsync(string orderId);
    
    /// <summary>
    /// 验证支付回调
    /// </summary>
    /// <param name="callbackData">回调数据</param>
    /// <returns>验证结果</returns>
    Task<PaymentResult> VerifyCallbackAsync(Dictionary<string, string> callbackData);
    
    /// <summary>
    /// 获取支付类型
    /// </summary>
    PaymentType PaymentType { get; }
    
    /// <summary>
    /// 是否支持当前平台
    /// </summary>
    bool IsSupportedPlatform { get; }
}

/// <summary>
/// 支付宝支付服务接口
/// </summary>
public interface IAlipayService : IPaymentService
{
    /// <summary>
    /// 获取支付宝授权信息
    /// </summary>
    /// <returns>授权信息</returns>
    Task<string> GetAuthInfoAsync();
    
    /// <summary>
    /// 处理支付宝回调
    /// </summary>
    /// <param name="result">支付结果</param>
    /// <returns>处理结果</returns>
    Task<PaymentResult> HandleAlipayResultAsync(string result);
}

/// <summary>
/// 微信支付服务接口
/// </summary>
public interface IWeChatPayService : IPaymentService
{
    /// <summary>
    /// 注册微信支付
    /// </summary>
    /// <param name="appId">应用ID</param>
    /// <returns>是否成功</returns>
    Task<bool> RegisterWeChatPayAsync(string appId);
    
    /// <summary>
    /// 检查微信是否安装
    /// </summary>
    /// <returns>是否安装</returns>
    Task<bool> IsWeChatInstalledAsync();
    
    /// <summary>
    /// 处理微信支付回调
    /// </summary>
    /// <param name="result">支付结果</param>
    /// <returns>处理结果</returns>
    Task<PaymentResult> HandleWeChatPayResultAsync(Dictionary<string, object> result);
}

/// <summary>
/// 支付管理服务接口
/// </summary>
public interface IPaymentManagerService
{
    /// <summary>
    /// 初始化支付管理服务
    /// </summary>
    /// <param name="config">支付配置</param>
    /// <returns>初始化任务</returns>
    Task InitializeAsync(PaymentConfig config);
    
    /// <summary>
    /// 检查支付是否可用
    /// </summary>
    /// <param name="paymentType">支付类型</param>
    /// <returns>是否可用</returns>
    Task<bool> IsPaymentAvailableAsync(PaymentType paymentType);
    
    /// <summary>
    /// 获取支付服务
    /// </summary>
    /// <param name="paymentType">支付类型</param>
    /// <returns>支付服务</returns>
    IPaymentService GetPaymentService(PaymentType paymentType);
    
    /// <summary>
    /// 注册支付服务
    /// </summary>
    /// <param name="paymentType">支付类型</param>
    /// <param name="service">支付服务</param>
    void RegisterPaymentService(PaymentType paymentType, IPaymentService service);
    
    /// <summary>
    /// 获取支持的支付类型
    /// </summary>
    /// <returns>支付类型列表</returns>
    IEnumerable<PaymentType> GetSupportedPaymentTypes();
    
    /// <summary>
    /// 统一支付接口
    /// </summary>
    /// <param name="request">支付请求</param>
    /// <returns>支付响应</returns>
    Task<PaymentResponse> PayAsync(PaymentRequest request);
    
    /// <summary>
    /// 统一查询接口
    /// </summary>
    /// <param name="orderId">订单号</param>
    /// <param name="paymentType">支付类型</param>
    /// <returns>支付结果</returns>
    Task<PaymentResult> QueryAsync(string orderId, PaymentType paymentType);
}